#include "include/gudb.h"
#include <stdio.h>
#include <stdlib.h>

int main() {
    printf("Testing gudb_open with server parameters...\n");
    
    // Use the same parameters as the server
    const char* data_dir = "/tmp/gudb_data";
    const char* username = "admin";
    const char* password = "admin";
    
    printf("Attempting to open database:\n");
    printf("  Data dir: %s\n", data_dir);
    printf("  Username: %s\n", username);
    printf("  Password: %s\n", password);
    
    gudb* db = gudb_open(data_dir, GU_OPEN_CREATE, username, password);
    
    if (!db) {
        printf("FAIL: gudb_open failed\n");
        printf("Error: %s\n", gudb_error(db));
        return 1;
    }
    
    printf("SUCCESS: Database opened successfully\n");
    
    // Test basic functionality
    gudb_txn* txn = gudb_begin(db, GU_TXN_RC, "gudb");
    if (txn) {
        printf("SUCCESS: Transaction started\n");
        
        result_t* result = NULL;
        if (gudb_exec(txn, "SHOW DATABASES", NULL, &result) == GU_OK) {
            printf("SUCCESS: SHOW DATABASES worked\n");
            printf("Found %u databases\n", result->row_count);
            gudb_free_result(result);
        } else {
            printf("FAIL: SHOW DATABASES failed\n");
        }
        
        gudb_commit(txn);
    } else {
        printf("FAIL: Could not start transaction\n");
    }
    
    gudb_close(db);
    printf("Database closed successfully\n");
    
    return 0;
}